﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using PragmaticMVC.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace PragmaticMVC.Tests.Models
{
    /// <summary>
    /// Summary description for UsersRolesContextTest
    /// </summary>
    [TestClass]
    public class UsersRolesContextTest
    {
       
     
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void GetUsers_Should_Return_UserCount()
        {
            // arrange
            const int actualUserCount = 4;

            // act
            var expectedUserCount = UsersRolesContext.GetUsers();

            // assert
            Assert.AreEqual( expectedUserCount, actualUserCount);
        }

        [TestMethod]
        public void GetUser_Returns_A_Valid_User()
        {
            // arrange
            const string userName = "janed";
            const string password = "janed";

            // act
            bool userExists = UsersRolesContext.GetUser(userName, password);

            // assert
            Assert.IsTrue(userExists);
        }

        [TestMethod]
        public void GetRolesByUser_Should_Return_A_List_Of_Roles()
        {
            const string userName = "johnf";

            var rolesList = UsersRolesContext.GetRolesForUser(userName);

            Assert.IsTrue(rolesList.Count() > 0);
        }

        [TestMethod]
        public void GetRolesByContext_Should_Return_A_List_Roles()
        {
            // arrange
            const string contextName = "AllowRegistration";

            // act
            var rolesList = UsersRolesContext.GetRolesByContext(contextName);

            // assert
            Assert.IsTrue(rolesList.Count() >0);
        }

        [TestMethod]
        public void IsUserInRole_Should_Return()
        {
            // arrange
            var userName = "bobj";
            string roleName = "Administrator";

            // act
            bool res = UsersRolesContext.IsUserInRole(userName, roleName);

            // assert
            Assert.IsTrue(res);
        }

        [TestMethod]
        public void IsRoleInContext_Should_Return()
        {
            // arrange
            string contextName = "AllowRegistration";
            string roleName = "Administrator";

            // act
            bool res = UsersRolesContext.IsRoleInContext(roleName, contextName);

            // assert
            Assert.IsTrue(res);
        }
    }
}
